import unittest


from taskpool import TaskRunner
from taskpool import ThreadPool
import time

class TestTaskPool(unittest.TestCase):
    def setUp(self):
        pass


    def tearDown(self):
        pass

    def testTaskPool(self):
        pool = ThreadPool(2,5)
        r1 = MyRunner1(pool)
        r2 = MyRunner2(pool)
        
        
        for i in range(10):
            r1.assign(i)
            print(str(i) + " assigned to " + "r1")
        
        for i in range(8):
            r2.assign(i)
            print(str(i) + " assigned to " + "r2")
        
        
        pool.stop()

class MyRunner1(TaskRunner):
    def process(self, task):
        print(str(task) + " processed")
        time.sleep(2)

class MyRunner2(TaskRunner):
    def process(self, task):
        print(str(task * 2) + " doubled")
        time.sleep(3)


suite = unittest.TestLoader().loadTestsFromTestCase(TestTaskPool)
if __name__ == '__main__':
    unittest.TextTestRunner(verbosity=2).run(suite)
